home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gdevpdfx.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-12  |  9.6 KB  |  321 lines

  1. /* Copyright (C) 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* Internal definitions for PDF-writing driver. */
  20. #include "gsparam.h"
  21. #include "gxdevice.h"
  22. #include "gxline.h"
  23. #include "stream.h"
  24. #include "gdevpstr.h"
  25. #include "gdevpsdf.h"
  26.  
  27. /* ---------------- Statically allocated sizes ---------------- */
  28. /* These should all really be dynamic.... */
  29.  
  30. /* Define the maximum size of the output file name. */
  31. #define fname_size 80
  32.  
  33. /* Define the maximum number of contents fragments on a page. */
  34. #define max_contents_ids 300
  35.  
  36. /* Define the maximum depth of an outline tree. */
  37. /* Note that there is no limit on the breadth of the tree. */
  38. #define max_outline_depth 8
  39.  
  40. /* Define the maximum size of a destination array string. */
  41. #define max_dest_string 80
  42.  
  43. /* ================ Types and structures ================ */
  44.  
  45. /* ---------------- Resources ---------------- */
  46.  
  47. typedef enum {
  48.   resourceFont,
  49.   resourceEncoding,
  50.   resourceFontDescriptor,
  51.   resourceColorSpace,
  52.   resourceXObject,
  53.   num_resource_types
  54. } pdf_resource_type;
  55. #define pdf_resource_type_names\
  56.   "Font", "Encoding", "FontDescriptor", "ColorSpace", "XObject"
  57. #define pdf_resource_type_structs\
  58.   &st_pdf_font, &st_pdf_resource, &st_pdf_resource, &st_pdf_resource,\
  59.   &st_pdf_resource
  60.  
  61. #define pdf_resource_common(typ)\
  62.     typ *next;            /* next resource of this type */\
  63.     pdf_resource *prev;        /* previously allocated resource */\
  64.     gs_id rid;            /* optional key */\
  65.     long id
  66. typedef struct pdf_resource_s pdf_resource;
  67. struct pdf_resource_s {
  68.     pdf_resource_common(pdf_resource);
  69. };
  70. #define private_st_pdf_resource()\
  71.   gs_private_st_ptrs2(st_pdf_resource, pdf_resource, "pdf_resource",\
  72.     pdf_resource_enum_ptrs, pdf_resource_reloc_ptrs, next, prev)
  73.  
  74. /* Font resources */
  75. typedef struct pdf_font_s pdf_font;
  76. struct pdf_font_s {
  77.     pdf_resource_common(pdf_font);
  78.     gs_const_string fname;
  79. };
  80. /****** Doesn't handle the string ******/
  81. #define private_st_pdf_font()\
  82.   gs_private_st_suffix_add0(st_pdf_font, pdf_font, "pdf_font",\
  83.     pdf_font_enum_ptrs, pdf_font_reloc_ptrs, st_pdf_resource)
  84.  
  85. /* ---------------- Other auxiliary structures ---------------- */
  86.  
  87. /* Outline nodes and levels */
  88. typedef struct pdf_outline_node_s {
  89.   long id, parent_id, prev_id, first_id, last_id;
  90.   int count;
  91.   gs_string action_string;
  92. } pdf_outline_node;
  93. typedef struct pdf_outline_level_s {
  94.   pdf_outline_node first;
  95.   pdf_outline_node last;
  96.   int left;
  97. } pdf_outline_level;
  98.  
  99. /* Articles */
  100. typedef struct pdf_bead_s {
  101.   long id, article_id, prev_id, next_id;
  102.   char dest[max_dest_string];
  103.   gs_rect rect;
  104. } pdf_bead;
  105. typedef struct pdf_article_s pdf_article;
  106. struct pdf_article_s {
  107.   pdf_article *next;
  108.   gs_string title;
  109.   long id;
  110.   pdf_bead first;
  111.   pdf_bead last;
  112. };
  113. /****** Doesn't handle the strings ******/
  114. #define private_st_pdf_article()\
  115.   gs_private_st_ptrs1(st_pdf_article, pdf_article, "pdf_article",\
  116.     pdf_article_enum_ptrs, pdf_article_reloc_ptrs, next)
  117.  
  118. /* Named destinations */
  119. typedef struct pdf_named_dest_s pdf_named_dest;
  120. struct pdf_named_dest_s {
  121.   pdf_named_dest *next;
  122.   gs_string key;
  123.   char dest[max_dest_string];
  124. };
  125. /****** Doesn't handle the string ******/
  126. #define private_st_pdf_named_dest()\
  127.   gs_private_st_ptrs1(st_pdf_named_dest, pdf_named_dest, "pdf_named_dest",\
  128.     pdf_named_dest_enum_ptrs, pdf_named_dest_reloc_ptrs, next)
  129.  
  130. /* ---------------- The device structure ---------------- */
  131.  
  132. /* Text state */
  133. typedef struct pdf_text_state_s {
  134.     float character_spacing;
  135.     pdf_font *font;
  136.     float size;
  137.     float word_spacing;
  138.     float horizontal_scaling;
  139. } pdf_text_state;
  140. #define pdf_text_state_default\
  141.   0, NULL, 0, 0, 100
  142.  
  143. /* Define the device structure. */
  144. typedef enum {
  145.   NoMarks = 0,
  146.   ImageB = 1,
  147.   ImageC = 2,
  148.   ImageI = 4,
  149.   Text = 8
  150. } pdf_procset;
  151. typedef enum {
  152.   pdf_in_none,
  153.   pdf_in_stream,
  154.   pdf_in_text
  155. } pdf_context;
  156. typedef struct gx_device_pdf_s {
  157.     gx_device_psdf_common;
  158.       /* PDF-specific distiller parameters */
  159.     float CompatibilityLevel;
  160.     bool DoThumbnails;        /* ****** OBSOLETE ****** */
  161.       /* End of distiller parameters */
  162.       /* Other parameters */
  163.     long FirstObjectNumber;
  164.       /* End of parameters */
  165.     bool binary_ok;            /* if true, OK to output binary info */
  166.         /* End of settable parameters. */
  167.         /* Following are set when device is opened. */
  168. #define pdf_memory v_memory
  169.     char tfname[fname_size + 1];
  170.     FILE *tfile;
  171.         /* ................ */
  172.     long next_id;
  173.         /* The following 2 IDs, and only these, are allocated */
  174.         /* when the file is opened. */
  175.     long root_id;
  176.     long info_id;
  177. #define pdf_num_initial_ids 2
  178.     long pages_id;
  179.     long outlines_id;
  180.     int next_page;
  181.     long contents_ids[max_contents_ids];
  182.     int next_contents_id;
  183.     pdf_context context;
  184.     long contents_length_id;
  185.     long contents_pos;
  186.     pdf_procset procsets;        /* used on this page */
  187.     float flatness;        /****** SHOULD USE state ******/
  188.     /* The line width, dash offset, and dash pattern */
  189.     /* are in default user space units. */
  190.     gx_line_params line_params;    /* current values */
  191.                 /****** SHOULD USE state ******/
  192. #define initial_num_page_ids 50
  193.     long *page_ids;
  194.     int num_page_ids;
  195.     int pages_referenced;
  196.     pdf_resource *resources[num_resource_types];
  197.     pdf_resource *annots;        /* rid = page # */
  198.     pdf_resource *last_resource;
  199.     gs_string catalog_string;
  200.     gs_string pages_string;
  201.     gs_string page_string;
  202.     pdf_outline_level outline_levels[max_outline_depth];
  203.     int outline_depth;
  204.     int closed_outline_depth;
  205.     int outlines_open;
  206.     pdf_article *articles;
  207.     pdf_named_dest *named_dests;
  208.     pdf_text_state text_state;
  209. } gx_device_pdf;
  210. #define is_in_document(pdev)\
  211.   ((pdev)->next_contents_id != 0 || (pdev)->last_resource != 0)
  212. #define is_in_page(pdev)\
  213.   ((pdev)->next_contents_id != 0)
  214.  
  215. /* ================ Utility procedures ================ */
  216.  
  217. /* ---------------- Exported by gdevpdf.c ---------------- */
  218.  
  219. /* ------ Document ------ */
  220.  
  221. /* Initialize the IDs allocated at startup. */
  222. void pdf_initialize_ids(P1(gx_device_pdf *pdev));
  223.  
  224. /* Open the document if necessary. */
  225. void pdf_open_document(P1(gx_device_pdf *pdev));
  226.  
  227. /* ------ Objects ------ */
  228.  
  229. /* Allocate an ID for a future object. */
  230. long pdf_obj_ref(P1(gx_device_pdf *pdev));
  231.  
  232. /* Begin an object, optionally allocating an ID. */
  233. long pdf_open_obj(P2(gx_device_pdf *pdev, long id));
  234.  
  235. /* Begin an object, allocating an ID. */
  236. #define pdf_begin_obj(pdev) pdf_open_obj(pdev, 0)
  237.  
  238. /* End an object. */
  239. int pdf_end_obj(P1(gx_device_pdf *pdev));
  240.  
  241. /* ------ Graphics ------ */
  242.  
  243. /* Set the fill or stroke color. */
  244. int pdf_set_color(P4(gx_device_pdf *pdev, gx_color_index color,
  245.              gx_drawing_color *pdcolor, const char *rgs));
  246.  
  247. /* Set the scale for coordinates according to the current resolution. */
  248. void pdf_set_scale(P1(gx_device_pdf *pdev));
  249.  
  250. /* ------ Page contents ------ */
  251.  
  252. /* Open a page contents part. */
  253. /* Return an error if the page has too many contents parts. */
  254. int pdf_open_contents(P2(gx_device_pdf *pdev, pdf_context context));
  255.  
  256. /* Close the current contents part if we are in one. */
  257. int pdf_close_contents(P2(gx_device_pdf *pdev, bool last));
  258.  
  259. /* ------ Resources et al ------ */
  260.  
  261. /* Begin an aside (resource, annotation, ...). */
  262. int pdf_begin_aside(P4(gx_device_pdf *pdev, pdf_resource **plist,
  263.                const gs_memory_struct_type_t *pst,
  264.                pdf_resource **ppres));
  265.  
  266. /* Begin a resource of a given type. */
  267. int pdf_begin_resource(P3(gx_device_pdf *pdev, pdf_resource_type type,
  268.               pdf_resource **ppres));
  269.  
  270. /* Find a resource of a given type by gs_id. */
  271. pdf_resource *pdf_find_resource_by_gs_id(P3(gx_device_pdf *pdev,
  272.                         pdf_resource_type type,
  273.                         gs_id rid));
  274.  
  275. /* End an aside. */
  276. int pdf_end_aside(P1(gx_device_pdf *pdev));
  277.  
  278. /* End a resource. */
  279. int pdf_end_resource(P1(gx_device_pdf *pdev));
  280.  
  281. /* ------ Pages ------ */
  282.  
  283. /* Reset the state of the current page. */
  284. void pdf_reset_page(P1(gx_device_pdf *pdev));
  285.  
  286. /* Get or assign the ID for a page. */
  287. /* Returns 0 if the page number is out of range. */
  288. long pdf_page_id(P2(gx_device_pdf *pdev, int page_num));
  289.  
  290. /* Open a page for writing. */
  291. int pdf_open_page(P2(gx_device_pdf *pdev, pdf_context context));
  292.  
  293. /* Write saved page- or document-level information. */
  294. int pdf_write_saved_string(P2(gx_device_pdf *pdev, gs_string *pstr));
  295.  
  296. /* Write the default entries of the Info dictionary. */
  297. int pdf_write_default_info(P1(gx_device_pdf *pdev));
  298.  
  299. /* ------ Path drawing ------ */
  300.  
  301. int pdf_put_clip_path(P2(gx_device_pdf *pdev, const gx_clip_path *pcpath));
  302.  
  303. /* ---------------- Exported by gdevpdfm.c ---------------- */
  304.  
  305. /* Compare a C string and a gs_param_string. */
  306. bool pdf_key_eq(P2(const gs_param_string *pcs, const char *str));
  307.  
  308. /* Process a pdfmark (called from pdf_put_params). */
  309. int pdfmark_process(P2(gx_device_pdf *pdev, const gs_param_string_array *pma));
  310.  
  311. /* Close the current level of the outline tree. */
  312. int pdfmark_close_outline(P1(gx_device_pdf *pdev));
  313.  
  314. /* Write an article bead. */
  315. int pdfmark_write_article(P2(gx_device_pdf *pdev, const pdf_bead *pbead));
  316.  
  317. /* ---------------- Exported by gdevpdft.c ---------------- */
  318.  
  319. /* Process a show operation (called from pdf_put_params). */
  320. int pdfshow_process(P2(gx_device_pdf *pdev, const gs_param_dict *ptd));
  321.